package com.application.outdoor.adapter;

import com.application.Activity.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AvatarAdapter extends BaseAdapter {
	private static class ViewHolder {
		TextView txtUser;
		ImageView imAvatar;
	}

	Context context;
	AvatarList data;
	LayoutInflater inflater;

	public AvatarAdapter(Context context, AvatarList data) {
		this.data = data;
		this.context = context;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return this.data.getSize();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			view = inflater.inflate(R.layout.row_avatar, null);
			ViewHolder holder = new ViewHolder();
			holder.imAvatar = (ImageView) view.findViewById(R.id.imAvatar);
			holder.txtUser = (TextView) view.findViewById(R.id.txtUser);
			view.setTag(holder);
		}
		
		ViewHolder holder = (ViewHolder) view.getTag();
		holder.imAvatar.setImageBitmap(data.get(position).getBmAvatar());
		holder.txtUser.setText(data.get(position).getUser());
		return view;
	}

}
